<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			var toGoatLatin = function(sentence) {
				let map = {
					a: true,
					e: true,
					i: true,
					o: true,
					u: true,
					A: true,
					E: true,
					I: true,
					O: true,
					U: true,
				};
				let arr = sentence.split(" ");
				for (let i = 0; i < arr.length; i++) {
					let cur = arr[i];
					if (!map[cur[0]]) {
						cur = cur.substring(1) + cur.substring(0, 1);
					}
					cur += "ma" + "a".repeat(i + 1);
					arr[i] = cur;
				}
				return arr.join(" ");
			};
			console.log(toGoatLatin("I speak Goat Latin"));
		</script>
	</body>
</html>
